<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="登录地址" prop="ipaddr">
        <el-input v-model="queryParams.ipaddr" placeholder="请输入登录地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户名称" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['caInfo:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
            v-hasPermi="['caInfo:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['caInfo:remove']">删除</el-button>
        </el-col>
        <el-button icon="el-icon-download" size="mini" @click="handleExport">导入</el-button>
        <el-button icon="el-icon-download" size="mini" @click="handleExport" type="danger" >下载导入模板</el-button>

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

    </el-form>
    <el-table v-loading="loading" :data="list.slice((pageNum - 1) * pageSize, pageNum * pageSize)" style="width: 100%;">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会话编号" align="center" prop="tokenId" :show-overflow-tooltip="true" />
      <el-table-column label="登录名称" align="center" prop="userName" :show-overflow-tooltip="true" />
      <el-table-column label="部门名称" align="center" prop="deptName" />
      <el-table-column label="平台名称" align="center" prop="deptName" />
      <el-table-column label="主机" align="center" prop="ipaddr" :show-overflow-tooltip="true" />
      <el-table-column label="登录地点" align="center" prop="loginLocation" :show-overflow-tooltip="true" />
      <el-table-column label="浏览器" align="center" prop="browser" />
      <el-table-column label="操作系统" align="center" prop="os" />
      <el-table-column label="登录时间" align="center" prop="loginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleup"
            v-hasPermi="['monitor:online:forceLogout']">操作记录</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleForceLogout(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']">强退</el-button>
        </template>
      </el-table-column>

    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" />

    <el-dialog :title="UpdateTitle" :visible.sync="UpdateOpen" width="700px" append-to-body>
      <el-table :data="tableData" height="250" style="width: 100%">
        <el-table-column prop="date" label="时间" width="280">
        </el-table-column>

        <el-table-column prop="content" label="内容">
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="showDetails(scope.row)"
              v-hasPermi="['monitor:online:forceLogout']">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog :visible.sync="detaile" width="700px" append-to-body>
      <el-form>
        <el-form-item label="操作详情" prop="ipaddr">

        </el-form-item>
      </el-form>

    </el-dialog>

    <el-dialog :visible.sync="popup"  append-to-body>
      <el-form :data="tableData" height="250"   label-width="88px">
        <el-form-item prop="name" label="账户名" >
          <el-input  placeholder="" />
        </el-form-item>

        <el-form-item prop="content" label="密码" >
          <el-input  placeholder="" />
        </el-form-item>
        <el-form-item prop="content" label="申请原因" >
          <el-input  placeholder="" type="textarea" row="2"/>
        </el-form-item>
        <el-form-item label="角色">
          <el-select v-model="dataBaseType" multiple placeholder="" style="width: 350px;">
            <el-option v-for="item in userOptions" :key="item.label" :label="item.label" :value="item.value">
            </el-option>
          </el-select>

        </el-form-item>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import { list, forceLogout } from "@/api/monitor/online";

export default {
  name: "Online",
  data() {
    return {
      userOptions:[
        {
          label:'超级管理员',
          value:1,
        },
        {
          label:'一般管理员',
          value:1,
        }

      ],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      tableData: [{
        date: '2023.10.15',
        content: '修改',
      }],
      pageNum: 1,
      single: true,
      pageSize: 10,
      UpdateOpen: false,
      multiple: true,
      showSearch: true,
      UpdateTitle: '',
      detaile: false,
      popup: false,
      // 查询参数
      queryParams: {
        ipaddr: undefined,
        userName: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleDelete() {

    },
    showDetails(data) {
      // this.reset();
      this.detaile = true;

      // this.getRulesList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleAdd(data) {
      // this.reset();
      this.popup = true;

      // this.getRulesList()
    },
    handleup(data) {
      // this.reset();
      this.UpdateOpen = true;
      console.log(data);
      this.title = "注册数据通道基本信息";
      this.shangchuanshow = data.id % 2 === 0;
      this.jieshoushow = !this.shangchuanshow;
      // this.getRulesList()
    },
    handleUpdate(data) {
      const id = data.id || this.selIds;
      DatabaseInfoById(id).then(res => {
        if (res.code === 200) {
          this.baseAddForm = res.data;
          if (this.baseAddForm.dataBaseType && this.baseAddForm.dataBaseType.length > 0) {
            this.dataBaseType = this.baseAddForm.databaseType.split(',')
          }

          this.UpdateTitle = "修改数据通道信息"
          this.UpdateOpen = true;
        } else {
          this.$message('获取数据通道信息失败')
        }
      })

    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$modal.confirm('是否确认强退名称为"' + row.userName + '"的用户？').then(function () {
        return forceLogout(row.tokenId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("强退成功");
      }).catch(() => { });
    }
  }
};
</script>

